package com.yiya.service;

import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yiya.bean.Merchant;
import com.yiya.bean.SysUser;
import com.yiya.mapper.MerchantMapper;
import com.yiya.model.MerchantModel;

@Service("merchantService")
public class MerchantService {

	@SuppressWarnings("unused")
	private final static Logger log = Logger.getLogger(MerchantService.class);

	@Autowired
	private MerchantMapper merchantMapper;

	public List<Merchant> queryByList(MerchantModel bean) {
		Integer rowCount = queryByCount(bean);
		bean.getPager().setRowCount(rowCount);
		List<Merchant> merchants = merchantMapper.selectByModel(bean);
		return merchants;
	}
	
	public int queryByCount(MerchantModel bean){
		return merchantMapper.countByModel(bean);
	}
	
	public int add(Merchant merchant){
		return merchantMapper.insert(merchant);
	}
	
	public int Update(Merchant merchant){
		return merchantMapper.updateByPrimaryKeySelective(merchant);
	}
	
	public Merchant queryById(Integer id){
		return merchantMapper.selectByPrimaryKey(id);
	}
	
	public void delete(Integer[] ids,SysUser user){
		Date nowTime = new Date();
		for(Integer id:ids){
			Merchant merchant = merchantMapper.selectByPrimaryKey(id);
			merchant.setUpdateBy(user.getId());
			merchant.setUpdateTime(nowTime);
			merchant.setDelFlag(1);
			merchantMapper.updateByPrimaryKeySelective(merchant);
		}
	}
	
	public List<Merchant> queryAllList(MerchantModel bean){
		return merchantMapper.queryAllList(bean);
	}

}
